using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Zhaoxi.Zhihu.Core.AppUserAggregate.Entites;

namespace Zhaoxi.Zhihu.Infrastructure.Configuration;

public class FollowQuestionConfiguration:IEntityTypeConfiguration<FollowQuestion>
{
    public void Configure(EntityTypeBuilder<FollowQuestion> builder)
    {
       //设置唯一约束
       builder
           .HasIndex(x => new { x.UserId, x.QuestionId })
           .IsUnique();
       //设置用户与关注问题之间的一对多关系
       builder
           .HasOne(fg=>fg.AppUser)
           .WithMany(u=>u.FollowQuestions)
           .HasForeignKey(fg=>fg.UserId)
           .IsRequired()
           .OnDelete(DeleteBehavior.NoAction);
    }
}